package flash.utils
{
import flash.interfaces.IDispose;
import flash.interfaces.ISafeGlobalInitiator;

public final dynamic class SafeGlobalProxy extends Proxy implements IDispose
{
	private var m_obInitiator:ISafeGlobalInitiator;
	private var m_obj:Object = new Object();
	private var m_blLocked:Boolean;
	/**
	 *
	 */
	public function SafeGlobalProxy()
	{
		super();
	}
//==================================================================================================
// public
//==================================================================================================
	public function dispose():void
	{
		if (m_obInitiator && m_obInitiator.allowDisposeSG)
		{
			/*中有在条件允许时才释放资源
			*/
			for (var k:String in m_obj)
			{
				delete m_obj[k];
			}
			m_obj = null;
		}
	}
	/**
	 * 锁定
	 */
	public function lock():void
	{
		m_blLocked = true;
	}
	/**
	 * 设置初始函数
	 */
	public function set initiator(value:ISafeGlobalInitiator):void
	{
		m_obInitiator = value;
	}
//==================================================================================================
// flash_proxy
//==================================================================================================
	/**
	 * 删除
	 */
	override flash_proxy function deleteProperty(name:*):Boolean
	{
		throw new Error("Connt delete ");
	}
	/**
	 * 
	 */
	override flash_proxy function getProperty(name:*):*
	{
		return m_obj[name];
	}
	/**
	 *
	 */
	override flash_proxy function setProperty(name:*, value:*):void
	{
		if (false == m_blLocked)
		{
			if (null == value || m_obj.hasOwnProperty(name))
			{
				/*不允许空或重复设置
				*/
				throw new Error("Repeated property or Null value");
			}
			else
			{
				m_obj[name] = value;
			}
		}
	}
}
}